<!DOCTYPE html>
<html  lang="zh-CN" >
    <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, maximum-scale=5, viewport-fit=cover">
    <title>集群双网卡互通问题解决方案 | 学为我用</title>
    <meta name="description" content="前言现在kafka集群上有内外网的两块网卡， 内网：10.109.251.[101-103] 外网：192.168.109.[101-103] 集群间是通过域名互通的，并且在host中使用内网地址 12310.109.251.101 kafka01.data.lan10.109.251.102 kafka02.data.lan10.109.251.103 kafka03.data.lan  在安装">
<meta property="og:type" content="article">
<meta property="og:title" content="集群双网卡互通问题解决方案">
<meta property="og:url" content="https://123zhangzhenbin.gitee.io/zzbomb/2020/08/26/202008261515-cluster-double-netcard/index.html">
<meta property="og:site_name" content="学为我用">
<meta property="og:description" content="前言现在kafka集群上有内外网的两块网卡， 内网：10.109.251.[101-103] 外网：192.168.109.[101-103] 集群间是通过域名互通的，并且在host中使用内网地址 12310.109.251.101 kafka01.data.lan10.109.251.102 kafka02.data.lan10.109.251.103 kafka03.data.lan  在安装">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2020-08-26T07:15:56.000Z">
<meta property="article:modified_time" content="2021-07-06T04:08:48.845Z">
<meta property="article:author" content="章瑱彬">
<meta property="article:tag" content="linux">
<meta name="twitter:card" content="summary">

    
    <link rel="icon" href="/zzbomb/images/favicon_128.ico" type="image/x-icon">

    
<link rel="stylesheet" href="/zzbomb/css/common.min.css">



    
    
    
    
        <link href="//cdn.jsdelivr.net/npm/lightgallery.js@1.1.3/dist/css/lightgallery.min.css" rel="stylesheet">
    
    
    
<link rel="stylesheet" href="/zzbomb/css/iconfont.min.css">

    
<meta name="generator" content="Hexo 4.2.1"></head>

    <body>
        <header class="header header-fixture">
    <div class="profile-search-wrap flex sm:block">
        
        
        <div class="profile sm:text-center md:px-1 lg:px-3 sm:pb-4 sm:pt-6">
            <a id="avatar" role="link" href="https://gitee.com/123zhangzhenbin" class="inline-block lg:w-16 lg:h-16 w-8 h-8 m-2" target="_blank" rel="noopener" rel="noreferrer" >
                <img src="/zzbomb/images/g.jpg" class="rounded-full" alt="avatar">
            </a>
            <h2 id="name" class="hidden lg:block">ZZB</h2>
            <h3 id="title" class="hidden xl:block">Java，大数据，人工智能，区块链</h3>
            
            <small id="location" class="hidden lg:block">
                <i class="iconfont icon-map-icon"></i>
                DongGuan, China
            </small>
            
        </div>
        
        
<div class="search flex-1 flex lg:inline-block sm:hidden lg:px-4 lg:mt-2 lg:mb-4 lg:w-full">
    <form id="search-form" class="my-auto flex-1 lg:border lg:border-solid lg:border-gray-200">
        <div class="input-group table bg-gray-100 lg:bg-white w-full">
            <input id="search-input" type="text" placeholder="搜索" class="inline-block w-full bg-gray-100 lg:bg-white">
            <span class="table-cell">
                <button name="search tigger button" disabled>
                    <i class="iconfont icon-search m-2"></i>
                </button>
            </span>
        </div>
    </form>
        
<script id="search-teamplate" type="text/html" data-path="/zzbomb/content.json">
    <div>
        <div class="search-header bg-gray-400">
            <input id="actual-search-input" model="keyword" ref="input" class="inline-block w-full h-10 px-2 py-1" placeholder="搜索" type="text">
        </div>
        <div class="search-result bg-gray-200">
            {{#each searchPosts}}
            <a href="/{{ path }}" class="result-item block px-2 pb-3 mb-1 pt-1 hover:bg-indigo-100">
                <i class="iconfont icon-file"></i>
                <h1 class="result-title inline font-medium text-lg">{{ title }}</h1>
                <p class="result-content text-gray-600 text-sm">{{{ text }}}</p>
            </a>
            {{/each}}
        </div>
    </div>
</script>

</div>


        <button name="menu toogle button" id="menu-toggle-btn" class="block sm:hidden p-3" role="button" aria-expanded="false">
            <i class="iconfont icon-hamburger"></i>
        </button>
    </div>
    <nav id="menu-nav" class="hidden sm:flex flex-col">
        
        
            <div class="menu-item menu-home" role="menuitem">
                <a href="/zzbomb/.">
                    <i class="iconfont icon-home" aria-hidden="true"></i>
                    <span class="menu-title">首页</span>
                </a>
            </div>
        
        
            <div class="menu-item menu-archives" role="menuitem">
                <a href="/zzbomb/archives">
                    <i class="iconfont icon-archive" aria-hidden="true"></i>
                    <span class="menu-title">归档</span>
                </a>
            </div>
        
        
            <div class="menu-item menu-categories" role="menuitem">
                <a href="/zzbomb/categories">
                    <i class="iconfont icon-folder" aria-hidden="true"></i>
                    <span class="menu-title">分类</span>
                </a>
            </div>
        
        
            <div class="menu-item menu-tags" role="menuitem">
                <a href="/zzbomb/tags">
                    <i class="iconfont icon-tag" aria-hidden="true"></i>
                    <span class="menu-title">标签</span>
                </a>
            </div>
        
        
            <div class="menu-item menu-repository" role="menuitem">
                <a href="/zzbomb/repository">
                    <i class="iconfont icon-project" aria-hidden="true"></i>
                    <span class="menu-title">项目</span>
                </a>
            </div>
        
        
            <div class="menu-item menu-links" role="menuitem">
                <a href="/zzbomb/links">
                    <i class="iconfont icon-friend" aria-hidden="true"></i>
                    <span class="menu-title">友链</span>
                </a>
            </div>
        
        
            <div class="menu-item menu-about" role="menuitem">
                <a href="/zzbomb/about">
                    <i class="iconfont icon-cup" aria-hidden="true"></i>
                    <span class="menu-title">关于</span>
                </a>
            </div>
        
        
<div class="social-links flex sm:flex-col lg:hidden mt-5">
    
        <span class="social-item text-center">
            <a href="https://gitee.com/123zhangzhenbin" target="_blank" rel="noopener">
                <i class="iconfont social-icon icon-github"></i>
                <span class="menu-title hidden lg:inline">menu.github</span>
            </a>
        </span>
    
</div>


    </nav>
</header>

        <section class="main-section">
            
    <main class="flex-1 px-4 py-12 md:px-5 lg:px-8 lg:py-4 relative min-h-screen">
    

    <article class="content article article-archives article-type-list" itemscope="">
        <header class="article-header">
            
    
        <h1 class="article-title text-lg" itemprop="name">
            集群双网卡互通问题解决方案
        </h1>
    



            <p class="article-meta mb-3 text-xs">
                <span class="article-date">
    <i class="iconfont icon-calendar-check"></i>
	<a href="/zzbomb/2020/08/26/202008261515-cluster-double-netcard/" class="article-date">
	  <time datetime="2020-08-26T07:15:56.000Z" itemprop="datePublished">8月 26</time>
	</a>
</span>

                

                
    <span class="article-tags">
    <i class="iconfont icon-tag"></i>
    <a class="article-tag-link" href="/zzbomb/tags/linux/" rel="tag">linux</a>
  </span>


                <span class="_partial/post-comment"><i class="icon icon-comment"></i>
                    <a href="/zzbomb/2020/08/26/202008261515-cluster-double-netcard/#comments" class="article-comment-link">
                        评论
                    </a>
                </span>
                

            </p>
        </header>
        <div class="marked-body article-body">
            <h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><p>现在kafka集群上有内外网的两块网卡，</p>
<p>内网：10.109.251.[101-103]</p>
<p>外网：192.168.109.[101-103]</p>
<p>集群间是通过域名互通的，并且在host中使用内网地址</p>
<figure class="highlight accesslog"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs accesslog"><span class="hljs-number">10.109.251.101</span> kafka01.data.lan<br><span class="hljs-number">10.109.251.102</span> kafka02.data.lan<br><span class="hljs-number">10.109.251.103</span> kafka03.data.lan<br></code></pre></td></tr></table></figure>

<p>在安装CDH时，有些服务默认绑定的是域名所在的网卡，也就是内网网卡，这样就会导致外网地址访问不到。在CDH有些服务可以通过绑定0.0.0.0通配地址，来解决这个问题（比如resourceManager和historyManager）但是有些服务无法配置【如nodeManager】，第一个想到的是通过iptables进行端口转发。虽然iptables 的功能当然强大，但理解与设置却有点抽象，并且在centos7中已经用firewall代替了。我们集群默认都是关闭firewall的，没有办法，只能另求他路。最终在网上找到了rinetd。</p>
<h2 id="简介"><a href="#简介" class="headerlink" title="简介"></a>简介</h2><p>Rinetd是为在一个Unix和Linux操作系统中为重定向传输控制协议(TCP)连接的一个工具。Rinetd是单一过程的服务器，它处理任何数量的连接到在配置文件etc/rinetd中指定的地址/端口对。尽管rinetd使用非闭锁I/O运行作为一个单一过程，它可能重定向很多连接而不对这台机器增加额外的负担。</p>
<p>Rinetd官网  <a href="https://boutell.com/rinetd/" target="_blank" rel="noopener">https://boutell.com/rinetd/</a></p>
<h2 id="安装"><a href="#安装" class="headerlink" title="安装"></a>安装</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><code class="hljs bash"><span class="hljs-built_in">cd</span> /opt/packages/<br>cat &gt;&gt; rinetd-installer.sh &lt;&lt;<span class="hljs-string">'EOF'</span><br><span class="hljs-meta">#!/bin/bash</span><br>wget http://www.boutell.com/rinetd/http/rinetd.tar.gz<br>tar zxvf rinetd.tar.gz<br><span class="hljs-built_in">cd</span> rinetd<br>mkdir -p /usr/man/man8<br><span class="hljs-comment"># make编译提示：make cc Command not found 解决办法 -&gt; yum安装gcc</span><br>yum install gcc<br>make &amp;&amp; make install<br>EOF<br>chmod +x rinetd-installer.sh<br>./rinetd-installer.sh<br></code></pre></td></tr></table></figure>

<h2 id="配置"><a href="#配置" class="headerlink" title="配置"></a>配置</h2><p>配置端口转发的配置文件在/etc/rinetd.conf</p>
<h3 id="配置文件格式"><a href="#配置文件格式" class="headerlink" title="配置文件格式"></a>配置文件格式</h3><p>[Source Address] [Source Port] [Destination Address] [Destination Port]<br>源地址 源端口 目的地址 目的端口<br>在每一单独的行中指定每个要转发的端口。源地址和目的地址都可以是主机名或IP地址，IP 地址0.0.0.0将rinetd绑定到任何可用的本地IP地址上。</p>
<p>比如当前需要把nodeManager的WEB地址的内网端口通过转发通过外网暴露，做如下配置</p>
<figure class="highlight angelscript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs angelscript">rm -f /etc/rinetd.conf<br>cat &gt;&gt; /etc/rinetd.conf &lt;&lt;EOF<br># 设置日志文件路径<br>logfile /var/log/rinetd.log<br># 例子: 将<span class="hljs-number">192.168</span><span class="hljs-number">.109</span><span class="hljs-number">.103</span> <span class="hljs-number">18044</span> 端口重定向至 <span class="hljs-number">10.109</span><span class="hljs-number">.251</span><span class="hljs-number">.103</span> 的 <span class="hljs-number">18044</span> 端口<br><span class="hljs-number">192.168</span><span class="hljs-number">.109</span><span class="hljs-number">.103</span> <span class="hljs-number">18044</span> <span class="hljs-number">10.109</span><span class="hljs-number">.251</span><span class="hljs-number">.103</span> <span class="hljs-number">18044</span><br>EOF<br></code></pre></td></tr></table></figure>

<h2 id="创建启动脚本"><a href="#创建启动脚本" class="headerlink" title="创建启动脚本"></a>创建启动脚本</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br></pre></td><td class="code"><pre><code class="hljs bash">cat &gt;&gt; /etc/init.d/rinetd &lt;&lt;<span class="hljs-string">'EOF'</span><br><span class="hljs-meta">#!/bin/bash</span><br>EXEC=/usr/sbin/rinetd<br>CONF=/etc/rinetd.conf<br>PID_FILE=/var/run/rinetd.pid<br>NAME=Rinetd<br>DESC=<span class="hljs-string">"Rinetd Server"</span><br> <br><span class="hljs-keyword">case</span> <span class="hljs-string">"<span class="hljs-variable">$1</span>"</span> <span class="hljs-keyword">in</span><br>    start)<br>        <span class="hljs-keyword">if</span> [ -x <span class="hljs-string">"<span class="hljs-variable">$PID_FILE</span>"</span> ]; <span class="hljs-keyword">then</span><br>            <span class="hljs-built_in">echo</span> <span class="hljs-string">"<span class="hljs-variable">$NAME</span> is running ..."</span><br>            <span class="hljs-built_in">exit</span> 0<br>        <span class="hljs-keyword">fi</span><br> <br>        <span class="hljs-variable">$EXEC</span> -c <span class="hljs-variable">$CONF</span><br> <br>        <span class="hljs-built_in">echo</span> -e <span class="hljs-string">"\e[1;32m<span class="hljs-variable">$NAME</span> is running\e[0m"</span><br>    ;;<br>    stop)<br>        <span class="hljs-keyword">if</span> [ -f <span class="hljs-string">"<span class="hljs-variable">$PID_FILE</span>"</span> ]; <span class="hljs-keyword">then</span><br>            <span class="hljs-built_in">kill</span> `cat <span class="hljs-variable">$PID_FILE</span>`<br> <br>            <span class="hljs-keyword">while</span> [ -x <span class="hljs-string">"<span class="hljs-variable">$PID_FILE</span>"</span> ]<br>            <span class="hljs-keyword">do</span><br>                <span class="hljs-built_in">echo</span> <span class="hljs-string">"Waiting for <span class="hljs-variable">$NAME</span> to shutdown..."</span> <br>                sleep 1<br>            <span class="hljs-keyword">done</span><br> <br>            rm -f <span class="hljs-variable">$PID_FILE</span><br>        <span class="hljs-keyword">fi</span><br> <br>        <span class="hljs-built_in">echo</span> -e <span class="hljs-string">"\e[1;31m<span class="hljs-variable">$NAME</span> stopped.\e[0m"</span><br>    ;;<br>    restart)<br>        <span class="hljs-variable">$0</span> stop<br>        <span class="hljs-variable">$0</span> start<br>    ;;<br>    status)<br>        <span class="hljs-keyword">if</span> [ -f <span class="hljs-variable">$PID_FILE</span> ]; <span class="hljs-keyword">then</span><br>            <span class="hljs-built_in">echo</span> <span class="hljs-string">"<span class="hljs-variable">$NAME</span> is running ..."</span><br>        <span class="hljs-keyword">else</span><br>            <span class="hljs-built_in">echo</span> <span class="hljs-string">"<span class="hljs-variable">$NAME</span> stopped."</span><br>        <span class="hljs-keyword">fi</span><br>    ;;<br>    *)<br>        <span class="hljs-built_in">echo</span> $<span class="hljs-string">"Usage: <span class="hljs-variable">$0</span> &#123;start|stop|restart|status&#125;"</span><br>        <span class="hljs-built_in">exit</span> 2<br>    ;;<br><span class="hljs-keyword">esac</span><br> <br><span class="hljs-built_in">exit</span> 0<br>EOF<br> <br> <br>chmod +x /etc/init.d/rinetd<br></code></pre></td></tr></table></figure>

<h2 id="启动服务"><a href="#启动服务" class="headerlink" title="启动服务"></a>启动服务</h2><figure class="highlight awk"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs awk"><span class="hljs-regexp">/etc/i</span>nit.d<span class="hljs-regexp">/rinetd start</span><br></code></pre></td></tr></table></figure>
<h2 id="开机启动"><a href="#开机启动" class="headerlink" title="开机启动"></a>开机启动</h2><figure class="highlight awk"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs awk">在<span class="hljs-regexp">/etc/</span>rc.local 文件中，添加<span class="hljs-regexp">/usr/</span>sbin<span class="hljs-regexp">/rinetd 或者 /u</span>sr<span class="hljs-regexp">/sbin/</span>rinetd -c <span class="hljs-regexp">/etc/</span>rinetd.conf 启动命令即可。<br></code></pre></td></tr></table></figure>

<h2 id="需要注意"><a href="#需要注意" class="headerlink" title="需要注意"></a>需要注意</h2><p>rinetd.conf中绑定的本机端口必须没有被其它程序占用</p>

        </div>
        
<blockquote class="copyright">
    <p><strong>本文链接 : </strong><a class="permalink" href="https://123zhangzhenbin.gitee.io/zzbomb/2020/08/26/202008261515-cluster-double-netcard/">https://123zhangzhenbin.gitee.io/zzbomb/2020/08/26/202008261515-cluster-double-netcard/</a></p>
    <p><strong>This article is available under <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank" rel="noopener noreferrer">Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)</a> License</strong></p>
</blockquote>


    </article>
    
    <section id="comments">
        
    </section>


    

</main>


<aside style="" id="sidebar" class="aside aside-fixture">
    <div class="toc-sidebar">
        <nav id="toc" class="article-toc">
            <h3 class="toc-title">文章目录</h3>
            <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#前言"><span class="toc-number">1.</span> <span class="toc-text">前言</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#简介"><span class="toc-number">2.</span> <span class="toc-text">简介</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#安装"><span class="toc-number">3.</span> <span class="toc-text">安装</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#配置"><span class="toc-number">4.</span> <span class="toc-text">配置</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#配置文件格式"><span class="toc-number">4.1.</span> <span class="toc-text">配置文件格式</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#创建启动脚本"><span class="toc-number">5.</span> <span class="toc-text">创建启动脚本</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#启动服务"><span class="toc-number">6.</span> <span class="toc-text">启动服务</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#开机启动"><span class="toc-number">7.</span> <span class="toc-text">开机启动</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#需要注意"><span class="toc-number">8.</span> <span class="toc-text">需要注意</span></a></li></ol>
        </nav>
    </div>
</aside>





        </section>
        <footer class="hidden lg:block fixed bottom-0 left-0 sm:w-1/12 lg:w-1/6 bg-gray-100 z-40">
    
    <div class="footer-social-links">
        
            <a href="https://gitee.com/123zhangzhenbin" target="_blank" rel="noopener">
                <i class="iconfont icon-github"></i>
            </a>
        
    </div>
    
    <p style="display: block;text-align: center;font-size: 13px;"><a href="https://beian.miit.gov.cn/" target="_blank">粤ICP备16013026号</a></p>
    
        <p class="footer-custom"><a href="https://beian.miit.gov.cn/" target="_blank">粤ICP备16013026号</a></p>
        <p class="theme-brand">Theme by <a href="https://github.com/fengkx/hexo-theme-purer" target="_blank" rel="nofollow noopener noreferrer noopener">hexo-theme-purer</a></p>

    
</footer>

        <div id="mask" class="hidden mask fixed inset-0 bg-gray-900 opacity-75 z-40"></div>
        <div id="search-view-container" class="hidden shadow-xl"></div>
        
<script src="/zzbomb/js/dom-event.min.js"></script>

<script src="//cdn.jsdelivr.net/npm/yox@1.0.0-alpha.121/dist/standard/prod/yox.min.js"></script>


<script src="/zzbomb/js/search.min.js"></script>



    <script src="//cdn.jsdelivr.net/npm/lightgallery.js@1.1.3/dist/js/lightgallery.min.js"></script>
    
<script src="/zzbomb/js/light-gallery.min.js"></script>





    </body>
</html>
